﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Cosmetic.Logic;
using System.Collections.Generic;
using Cosmetic.DataEntity;

namespace WebApp.Controls
{
    public partial class ThemePlate3 : System.Web.UI.UserControl
    {
        PlateManager PM = new PlateManager();
        AdvertiseManager theAdvertiseManager = new AdvertiseManager();

        protected void Page_Load(object sender, EventArgs e)
        {
            this.ListView1.DataSource = PM.GetPlateHouseHold();
            this.ListView1.DataBind();
            BindImage();
            BindTopLinks();
            BindBottomAd();
        }

        protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            HyperLink hl = e.Item.FindControl("HyperLink1") as HyperLink;
            if (hl.Text.Length > 8)
            {
                hl.Text = hl.Text.Substring(0, 8);
            }
        }

        private void BindImage()
        {
            Cosmetic.DataEntity.PlateHouseHoldBigPic pjc = theAdvertiseManager.GetPlateHouseHoldBigPic();
            this.imgBigPic.ImageUrl = pjc.PicUrl;
            //this.HyperLink5.NavigateUrl = pjc.PicUrl;
        }

        private void BindTopLinks()
        {
            List<Cosmetic.DataEntity.PlateHouseHoldPlaceHolder> listHolder = theAdvertiseManager.GetPlateHouseHoldPlaceHolderTOP();
            this.rptTopLink.DataSource = listHolder;
            this.rptTopLink.DataBind();
        }

        private void BindBottomAd()
        {
            Cosmetic.DataEntity.PlateExcellentClothBigPic pjc = theAdvertiseManager.GetPlateClothBigPic();

            List<Cosmetic.DataEntity.PlateHouseHoldPlaceHolder> listHolder = theAdvertiseManager.GetPlateHouseHoldPlaceHolderLEFT();
            if (!pjc.IsLeftPositionPic.Value)
            {
                List<Cosmetic.DataEntity.PlateHouseHoldPlaceHolder> listNotPic = listHolder.Where(c => c.IsPic != true).ToList();
                rptLeftLinks.DataSource = listNotPic;
                rptLeftLinks.DataBind();
                this.PLLeftPic.Visible = false;
                this.PLLeftNotPic.Visible = true;
            }
            else
            {
                List<Cosmetic.DataEntity.PlateHouseHoldPlaceHolder> listPic = listHolder.Where(c => c.IsPic == true).ToList();
                PlateHouseHoldPlaceHolder pjcp = listPic.First();
                this.imgLeftPic.ImageUrl = pjcp.PicUrl;

                this.PLLeftPic.Visible = true;
                this.PLLeftNotPic.Visible = false;
            }

            List<Cosmetic.DataEntity.PlateHouseHoldPlaceHolder> listHolderRight = theAdvertiseManager.GetPlateHouseHoldPlaceHolderRIGHT();

            //if (!pjc.IsRightPositionPic.Value)
            //{
            //    List<Cosmetic.DataEntity.PlateHouseHoldPlaceHolder> listNotPic = listHolderRight.Where(c => c.IsPic != true).ToList();
            //    rptRightLinks.DataSource = listNotPic;
            //    rptRightLinks.DataBind();
            //    this.PLRightPic.Visible = false;
            //    this.PLRightNotPic.Visible = true;
            //}
            //else
            //{
            //    List<Cosmetic.DataEntity.PlateHouseHoldPlaceHolder> listPic = listHolderRight.Where(c => c.IsPic == true).ToList();
            //    PlateHouseHoldPlaceHolder pjcp = listPic.First();
            //    this.imgRightPic.ImageUrl = pjcp.PicUrl;

            //    this.PLRightPic.Visible = true;
            //    this.PLRightNotPic.Visible = false;
            //}
        }
    }
}